package xhwl.insurance.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.math.BigDecimal;
import java.util.List;

import xhwl.android.common.util.SPUtil;
import xhwl.android.common.util.StringUtil;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.R;
import xhwl.insurance.http.api.OrderDescApi;
import xhwl.insurance.http.bean.resp.AllOrderDescReturnBean;
import xhwl.retrofitrx.BaseApi;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;


public class OrderDescPaymentActivity extends BaseActivity implements
		OnClickListener {
	private String sj_type;
	private String order_id;
	private TextView tv_paystatus;
	private TextView order_time;
	private TextView hospitaldesc_name;
	private TextView hospitaldesc_descaddress;
	private TextView order_price;
	private TextView order_content;
	private TextView order_number;
	private List<AllOrderDescReturnBean> mylist;
	private AllOrderDescReturnBean bean;
	private Button order_button;
	private ImageLoader loader;
	private TextView tv_needpay;
	TextView orderdesc_membername;
	Button orderdesc_confirmpayment;
	Button orderdesc_nowpayment;
	Button orderdesc_cancelorder;
	private ImageView img_erweima;
	private ImageView img_paymentstatus;
	private TextView tv_paymentstatus;
	private LinearLayout linear_erweima;
	private TextView yuyue_timepayment;
	private LinearLayout linear_yuyue_timepayment;
	private String order_name;
	private LinearLayout orderdescpayment_linear_phone;
	private LinearLayout orderdescpayment_linear_address;
	private LinearLayout orderdescpayment_linear_drugstore;
	private LinearLayout orderdesc_linear_consult_doctor;
	private TextView orderdesc_consult_doctor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_order_desc_payment);
	}

	public void initViews() {

		initTitleViews();
		Intent intent = getIntent();
		sj_type = intent.getStringExtra("sj_type");
		order_id = intent.getStringExtra("order_id");
		order_name = intent.getStringExtra("ordername");
		orderdesc_linear_consult_doctor = (LinearLayout) findViewById(R.id.orderdesc_linear_consult_doctor);
		orderdescpayment_linear_drugstore = (LinearLayout) findViewById(R.id.orderdescpayment_linear_drugstore);
		orderdescpayment_linear_address = (LinearLayout) findViewById(R.id.orderdescpayment_linear_address);
		orderdescpayment_linear_phone = (LinearLayout) findViewById(R.id.orderdescpayment_linear_phone);
		orderdesc_consult_doctor = (TextView) findViewById(R.id.orderdesc_consult_doctor);
		tv_paystatus = (TextView) findViewById(R.id.tv_paystatuspayment);
		order_time = (TextView) findViewById(R.id.order_timepayment);
		hospitaldesc_name = (TextView) findViewById(R.id.hospitaldesc_namepayment);
		hospitaldesc_descaddress = (TextView) findViewById(R.id.hospitaldesc_descaddresspayment);
		order_price = (TextView) findViewById(R.id.order_pricepayment);
		order_content = (TextView) findViewById(R.id.order_contentpayment);
		order_number = (TextView) findViewById(R.id.order_numberpayment);
		orderdesc_membername = (TextView) findViewById(R.id.orderdesc_membernamepayment);
		img_erweima = (ImageView) findViewById(R.id.img_erweima);
		img_paymentstatus = (ImageView) findViewById(R.id.img_paymentstatus);
		tv_paymentstatus = (TextView) findViewById(R.id.tv_paymentstatus);
		linear_erweima = (LinearLayout) findViewById(R.id.linear_erweima);
		yuyue_timepayment = (TextView) findViewById(R.id.yuyue_timepayment);
		linear_yuyue_timepayment = (LinearLayout) findViewById(R.id.linear_yuyue_timepayment);

	}

	@Override
	protected void setUpTitleView() {
		titleTextView.setText("订单详情");
		// TODO Auto-generated method stub
		super.setUpTitleView();
	}

	@Override
	public void initListener() {
		// order_button.setOnClickListener(this);
	}

	@Override
	public void loadData() {
		String memberId = SPUtil.getPersonInfoSp().getString(SPUtil.SPPersonInfo.MEMBER_ID,
				"");
		if (StringUtil.isEmpty(memberId)) {
			return;
		}
		BaseApi api=new OrderDescApi(memberId,order_id,sj_type);
		HttpManager.getInstance().dealHttp(this, api, new OnNextListener<String>() {
			@Override
			public void onNext(String data) {
				try {
					bean = new Gson().fromJson(data, AllOrderDescReturnBean.class);

					if (bean.getORDER_STATUS().equals("消费成功")) {
						tv_paymentstatus.setText("已完成");
						linear_erweima.setVisibility(View.GONE);
					}

					order_time.setText(bean.getCREATE_DATE());
					if (bean.getHOS_NAME() == null) {
						hospitaldesc_name.setText("预约药店: " + "暂无数据");
					} else {
						hospitaldesc_name.setText("预约药店: " + bean.getHOS_NAME());
					}
					if (bean.getHOS_ADDRESS() == null) {
						hospitaldesc_descaddress.setText("药店地址: " + "暂无数据");
					} else {
						hospitaldesc_descaddress.setText("药店地址: "
								+ bean.getHOS_ADDRESS());
					}
					if (order_name.equals("在线咨询")) {
						tv_paystatus.setText(bean.getORDER_STATUS() + "--无需核销");
					} else if (order_name.equals("患者根据处方订单下单")&&!bean.getORDER_STATUS().equals("消费成功")) {
						tv_paystatus.setText(bean.getORDER_STATUS() + "--待核销");
						orderdesc_linear_consult_doctor.setVisibility(View.VISIBLE);
					} else {
						tv_paystatus.setText(bean.getORDER_STATUS());

					}

					order_price.setText("¥"
							+ new BigDecimal(bean.getORDER_MONEY()).setScale(2,
							BigDecimal.ROUND_HALF_UP));
					order_content.setText(bean.getSERVE_NAME());
					orderdesc_consult_doctor.setText("咨询医生: "+bean.getEXPERT_NAME());
					if (order_name.equals("购买百倍爱心卡")
							&& bean.getORDER_STATUS().equals("待付款")) {
						img_paymentstatus.setImageDrawable(getResources().getDrawable(
								R.drawable.bookzhong));
						tv_paymentstatus.setText("待付款");
						tv_paymentstatus.setTextColor(getResources().getColor(
								R.color.orange));
					}
					if (order_name.equals("购买百倍爱心卡") || order_name.equals("购买远程会诊服务")
							|| order_name.equals("在线咨询")) {
						order_content.setText(order_name);
						linear_erweima.setVisibility(View.GONE);
						orderdescpayment_linear_phone.setVisibility(View.GONE);
						orderdescpayment_linear_address.setVisibility(View.GONE);
						orderdescpayment_linear_drugstore.setVisibility(View.GONE);
					}
					order_number.setText(bean.getORDER_ID());
					orderdesc_membername.setText("会员姓名: " + bean.getMEMBER_NAME());


				} catch (Exception e) {
					// TODO: handle exception
				}

			}
		});
	}
	@Override
	public void onClick(View v) {

	}
}
